@extends('Admin.layout.layout')
@section('title','分区列表')
@section('content')
	<div class="row">
		<div class="col-lg-12">
			<h1 class="page-header">分区列表</h1>
		</div>
		<!-- /.col-lg-12 -->
	</div>
	<div class="panel-body"> 
   		<div class="dataTable_wrapper"> 
    		<div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
    			<div class="row">
    				<form action="{{url('/admin/part/index')}}" method="get">
	      				<div class="col-sm-6">
	       					<div class="dataTables_length" id="dataTables-example_length">
	        					<label>每页显示 
		        					<select name="num" aria-controls="dataTables-example" class="form-control input-sm">
			        					<option value="10" @if(!empty($request['num']) && $request['num'] == 10) selected @endif>10</option>
			        					<option value="25" @if(!empty($request['num']) && $request['num'] == 25) selected @endif>25</option>
			        					<option value="50" @if(!empty($request['num']) && $request['num'] == 50) selected @endif>50</option>
			        					<option value="100"  @if(!empty($request['num']) && $request['num'] == 100) selected @endif>100</option>
		        					</select> 条
		        				</label>
	       					</div>
	      				</div>
		      			<div class="col-sm-6">
			       			<div id="dataTables-example_filter" class="dataTables_filter">
			        			<label>分区名:<input name="keywords" value="@if(!empty($request['keywords'])){{$request['keywords']}}@endif" class="form-control input-sm" placeholder="" aria-controls="dataTables-example" type="search" /></label>
			       				<button class="btn btn-primary">查询</button>
			       			</div>
		      			</div>
      				</form>
     			</div>
     			<div class="row">
      				<div class="col-sm-12">
				       	<table class="table table-striped table-bordered table-hover dataTable no-footer" id="dataTables-example" role="grid" aria-describedby="dataTables-example_info"> 
				        	<thead> 
				         		<tr role="row">
						        	<th class="sorting_asc" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1" aria-sort="ascending">ID</th>
						        	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1">分区名</th>
						        	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1">状态</th>
						        	<th class="sorting" tabindex="0" aria-controls="dataTables-example" rowspan="1" colspan="1">操作</th>
						        </tr> 
				        	</thead> 
					        <tbody> 
						        @foreach($parts as $k=>$v)
							    <tr class="gradeA odd" role="row">
							        <td class="sorting_1 sid">{{$v->id}}</td>
							        <td>{{$v->partname}}</td>
							        <td class="center">{{str_replace([1,2],['不显示','显示'],$v->status)}}</td>
							        <td class="center">
								        <a href="{{url('/admin/part/delete',['id'=>$v->id])}}" class="fa fa-trash-o delete">删除</a>
								        &nbsp;|&nbsp;
								        <a href="{{url('/admin/part/edit',['id'=>$v->id])}}" class="fa fa-wrench">修改</a>
							        </td>
							    </tr>
								@endforeach
					        </tbody> 
	       				</table>
      				</div>
     			</div>
			    <div class="row">
				    <div class="col-sm-6">
				    </div>
				    <div class="col-sm-6">
					    <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
					        {!! $parts->appends($request)->render() !!}
					    </div>
				    </div>
     			</div>
    		</div> 
   		</div> 
  	</div>
@endsection
@section('myjs')
<script type="text/javascript">
$.ajaxSetup({
    headers: {
        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
});
  	$('.delete').click(function(){
  		var id = $(this).parents('tr').find('.sid').html();
  		// alert(id);
  		var dd = $(this);
  		//发送ajax
  		$.post('/admin/part/delete',{id:id},function(data){
  			if(data == 1){
  				dd.parents('tr').remove();
  				alert('删除成功');
  			}
  			if(data == 2){
  				alert('删除失败');
  			}
  			if(data == 3){
  				alert('该分区下有版块不能删除');
  			}
  		})
  		return false;
  	})
</script>
@endsection